<template>
  <div class="mod-live-liveProdStore">
    <avue-crud
      ref="crud"
      :page="page"
      :data="dataList"
      :table-loading="dataListLoading"
      :option="tableOption"
      @search-change="searchChange"
      @on-load="getDataList"
      @refresh-change="refreshChange"
    >
      <template slot="menuLeft">
        <!-- <el-button icon="el-icon-plus" type="primary" size="small" @click="addOrUpdateHandle()">新增</el-button> -->
        <span
          style="color:red;"
        >{{$t('liveRoom.newLiveProdNum') + $t('liveRoom.platformRemainingQuota')}} {{totalNum}} {{$t('distribution.bcTip4')}}</span>
      </template>
      <template slot-scope="scope" slot="coverPic" class="prod-image">
        <img :src="scope.row.coverPic" width="60" height="60" />
        <span class="name">{{scope.row.name}}</span>
      </template>
      <template slot-scope="scope" slot="status">
        <el-tag size="mini" v-if="scope.row.status === -1">{{$t('liveRoom.goodsDeleted')}}</el-tag>
        <el-tag size="mini" v-if="scope.row.status === 0">{{$t('liveRoom.notReviewed')}}</el-tag>
        <el-tag size="mini" v-if="scope.row.status === 1">{{$t('liveRoom.underReview')}}</el-tag>
        <el-tag size="mini" v-if="scope.row.status === 2">{{$t('liveRoom.approved')}}</el-tag>
        <el-tag size="mini" v-if="scope.row.status === 3">{{$t('liveRoom.auditFailed')}}</el-tag>
        <el-tag size="mini" v-if="scope.row.status === 4">{{$t('product.violation')}}</el-tag>
        <el-tag size="mini" v-if="scope.row.status === 5">{{$t('scoreProdList.platformOffShelf')}}</el-tag>
      </template>
      <template slot-scope="scope" slot="price">
        <div v-if="scope.row.priceType == 1">
          <span>￥{{scope.row.price}}</span>
        </div>
        <div v-if="scope.row.priceType == 2">
          <span>￥{{scope.row.price}} {{$t('coupon.yuan')}} - ￥{{scope.row.price2}} {{$t('coupon.yuan')}}</span>
        </div>
        <div v-if="scope.row.priceType == 3">
          <span>{{$t('prodList.marketValue')}} ￥{{ scope.row.price}} {{$t('coupon.yuan')}}</span>
          <br />
          <span>{{$t('product.price')}} ￥{{ scope.row.price2}} {{$t('coupon.yuan')}}</span>
        </div>
      </template>
      <template slot-scope="scope" slot="menu">
        <!--
        <el-button
          v-if="scope.row.status === 0 || scope.row.status === 3"
          icon="el-icon-edit"
          :disabled="scope.row.status === 1"
          size="small"
          type="text"
          @click="addOrUpdateHandle(scope.row.liveProdStoreId)"
        >修改</el-button>
        <el-button
          v-if="scope.row.status === 2 || scope.row.status === 5"
          icon="el-icon-edit"
          size="small"
          type="text"
          @click="addOrUpdateHandle(scope.row.liveProdStoreId)"
        >更新信息</el-button>

        <el-button
          v-if="scope.row.status === 0 || scope.row.status === 5"
          icon="el-icon-edit"
          size="small"
          type="text"
          @click="submitVerify(scope.row.liveProdStoreId)"
        >{{scope.row.status === 5?'重新审核':'提交审核'}}</el-button>
        -->
        <el-button
          :disabled="scope.row.status === 1"
          type="text"
          icon="el-icon-delete"
          size="small"
          style="color:red"
          @click="deleteHandle(scope.row.liveProdStoreId)"
        >{{$t('remindPop.delete')}}</el-button>
      </template>
    </avue-crud>
    <!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="refreshChange"></add-or-update> -->
  </div>
</template>

<script>
import { tableOption } from '@/crud/live/liveProdStore'
// import AddOrUpdate from './liveProdStore-add-or-update'
export default {
  data () {
    return {
      dataList: [],
      shopNum: 0,
      totalNum: 0,
      deleteShopNum: 0,
      deleteTotalNum: 0,
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      searchForm: {}, // 搜索
      dataListLoading: false,
      tableOption: tableOption,
      resourcesUrl: window.SITE_CONFIG.resourcesUrl,
      addOrUpdateVisible: false
    }
  },
  components: {
    // AddOrUpdate
  },
  created () {
  },
  mounted () {
  },
  methods: {
    getDataList (page) {
      this.dataListLoading = true
      this.getAddProdNum()
      this.$http({
        url: this.$http.adornUrl('/platform/live/liveProdStore/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign(
            {
              current: page == null ? this.page.currentPage : page.currentPage,
              size: page == null ? this.page.pageSize : page.pageSize
            },
            this.searchForm
          )
        )
      }).then(({ data }) => {
        this.dataList = data.records
        this.page.total = data.total
        this.dataListLoading = false
      })
    },
    // 获取剩余可新增得数量
    getAddProdNum () {
      this.$http({
        url: this.$http.adornUrl('/platform/live/liveProdStore/getAddProdNum'),
        method: 'get',
        params: this.$http.adornParams()
      }).then(({ data }) => {
        this.shopNum = data.shopNum
        this.totalNum = data.totalNum
        this.deleteShopNum = data.deleteShopNum
        this.deleteTotalNum = data.deleteTotalNum
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      // this.addOrUpdateVisible = true
      // this.$nextTick(() => {
      //   this.$refs.addOrUpdate.init(id)
      // })
    },
    /**
     * 提交审核
     */
    submitVerify (id) {
      this.$confirm(this.$i18n.t('liveRoom.auditNeeds') + ' 1 - 7 ' + this.$i18n.t('liveRoom.day') + '，' + this.$i18n.t('liveRoom.confirmSubmit') + '？', this.$i18n.t('liveRoom.submitReview'), {
        confirmButtonText: this.$i18n.t('remindPop.confirm'),
        cancelButtonText: this.$i18n.t('remindPop.cancel'),
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/live/liveProdStore/submitVerify'),
          method: 'put',
          data: this.$http.adornData({
            liveProdStoreId: id
          })
        }).then(({ data }) => {
          if (data) {
            this.$message({
              message: this.$i18n.t('liveRoom.submitReview'),
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.refreshChange()
              }
            })
          }
        })
      }).catch(() => { })
    },
    deleteHandle (id) {
      this.$confirm(this.$i18n.t('liveRoom.delTips') + ' ' + this.deleteTotalNum + this.$i18n.t('distribution.bcTip4') + ',' + this.$i18n.t('seckill.isDeleOper'), this.$i18n.t('remindPop.remind'), {
        confirmButtonText: this.$i18n.t('remindPop.confirm'),
        cancelButtonText: this.$i18n.t('remindPop.cancel'),
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/platform/live/liveProdStore/' + id),
          method: 'delete',
          data: this.$http.adornData({})
        }).then(({ data }) => {
          this.$message({
            message: this.$i18n.t('remindPop.success'),
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.refreshChange()
            }
          })
        })
      }).catch(() => { })
    },
    /**
     * 刷新回调
     */
    refreshChange () {
      this.page = this.$refs.crud.$refs.tablePage.defaultPage
      this.getDataList(this.page)
    },
    searchChange (params) {
      this.searchForm = params
      this.getDataList(this.page)
    }
  }
}
</script>
<style lang="scss">
.mod-live-liveProdStore {
  .prod-image {
    display: flex;
    align-items: center;
  }
  .prod-image .name {
    margin-left: 10px;
    line-height: 20px;
  }
}
</style>
